const { contextBridge, ipcRenderer } = require('electron')
// const { electronAPI } = require('@electron-toolkit/preload')
const { electronAPI } = require('@electron-toolkit/preload')
// Custom APIs for renderer
const api = {
  // 这里可以添加你需要暴露给渲染进程的方法
}

if (process.contextIsolated) {
  try {
    contextBridge.exposeInMainWorld('electron', electronAPI)
    contextBridge.exposeInMainWorld('api', api)
    contextBridge.exposeInMainWorld('ipcRenderer', {
      send: (channel, data) => ipcRenderer.send(channel, data),
      on: (channel, func) => {
        ipcRenderer.on(channel, (event, ...args) => func(...args))
      }
    })
  } catch (error) {
    console.error(error)
  }
} else {
  window.electron = electronAPI
  window.api = api
}
